********************************************************************************
*************************************** ELS 2002 ******************************* 
********************************************************************************

********************************************************************************
*************************************** Round 2 ******************************** 
********************************************************************************	
	
	clear all
	set more off
	set maxvar 15000
	
	use "C:\Users\EAsker\Desktop\ABR\els_02\RFELS02_data\ELS2002_stdnt.dta",clear 

	rename *, lower
	
	/* base year variables: 1: Father's Education 2: Mother's Education 
	3: Family Income 4: Child's Race 5: Child's Gender*/
	
	rename (bymothed byfathed byincome byrace bysex bystuwt ncesdi bystate) ///
	(mot_edu fat_edu fam_inc race_by sex_by by_weight ncesid fips_state)
		
	gen survey=2002
	label var survey "Survey Year"
	gen wave=2
	label var wave "Survey time: three waves at most (2 Years Aft HS)"

	gen weight=f1qwt
	
	ren byregion region
	label var region "schools' region"
	
	recode mot_edu (1=0) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8=7) (-9/-4=.)
	gen mot_hs=mot_edu>=1 if mot_edu~=.
	
	recode fat_edu (1=0) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8=7) (-9/-4=.)
	gen fat_hs=fat_edu>=1 if fat_edu~=.
	
	label var fat_hs "Dummy: 1 if respondent's father graduted from a HS"
	label var mot_hs "Dummy: 1 if respondent's mother graduted from a HS"
	
	recode fam_inc (1=0) (2=1000) (3=5000) (4=10000) (5=15000) ///
	(6=20000) (7=25000) (8=35000) (9=50000) (10=75000) (11=100000) ///
	(12=200000) (13=300000)
	
	replace fam_inc=fam_inc*(237/177.1) //multiplying with the deflator
	label var fam_inc "Family income adjusted for inflation"
	
	recode race_by (-8/-4=.)
	gen white=race_by==7 if race_by~=.
	gen black=race_by==3 if race_by~=.
	gen hispanic=race_by==4|race_by==5 if race_by~=.
	gen oth_race=race_by==1|race_by==2|race_by==6 if race_by~=.
	
	recode sex_by (-8/-4=.)
	gen female=sex_by==2 if sex_by~=.
	
	gen not_white=.
		replace not_white=1 if black==1|hispanic==1|oth_race==1
		replace not_white=0 if white==1
	
	label var white "Dummy: 1 if respondent is a white"
	label var black "Dummy: 1 if respondent is black"
	label var hispanic "Dummy: 1 if respondent is hispanic"
	label var oth_race "Dummy: 1 if respondent is other race"
	label var female "Dummy: 1 if respondent is female"
	
	
	***** The following voluntary type questions have been asked recent HS grad (2004)
	 rename f1s62 hs_com_vol_2yrs
	 recode hs_com_vol_2yrs (-9/-1=.)
	 
	 gen hs_yes_com_vol_2yrs=hs_com_vol_2yrs==1 if hs_com_vol_2yrs~=.
	 label var hs_yes_com_vol_2yrs ///
	 "Dummy: 1 During the past 2 yrs, have you perform any vol or com serv work"
	 
	*************
	* Voluntary Particapation
	gen vltnry_prtcptn1=1 if hs_yes_com_vol_2yrs==1
	replace vltnry_prtcptn1=0 if hs_yes_com_vol_2yrs==0
	label var vltnry_prtcptn1 "Dummy:1 if respondent ever involved in voluntary activities"
	
	order ncesid survey wave
	drop if ncesid==-8|ncesid==-3
	
	* High School
	recode f2hsstat (10=.)
	gen hs1_high_sch=1 if f2hsstat==1|f2hsstat==2
	replace hs1_high_sch=0 if f2hsstat==3|f2hsstat==4|f2hsstat==5|f2hsstat==6
	label var hs1_high_sch "Dummy: 1 if repondent has a HS diploma"
	
	keep fips_state ncesid survey wave stu_id sch_id mot_hs fat_hs white ///
	black hispanic oth_race female fam_inc weight ///
	vltnry_prtcptn1 region not_white hs1_high_sch
	
	save  "C:\Users\EAsker\Desktop\ABR\els_02\RFELS02_Clean_data\Round_1_RFELS02.dta", replace 
	 	 
********************************************************************************
*************************************** Round 2 ******************************** 
********************************************************************************	 
	clear all
	set more off
	set maxvar 15000
	
	use "C:\Users\EAsker\Desktop\ABR\els_02\RFELS02_data\ELS2002_stdnt.dta",clear 

	rename *, lower
	
	/* base year variables: 1: Father's Education 2: Mother's Education 
	3: Family Income 4: Child's Race 5: Child's Gender*/
	
	rename (bymothed byfathed byincome byrace bysex bystuwt ncesdi bystate) ///
	(mot_edu fat_edu fam_inc race_by sex_by by_weight ncesid fips_state )
		
	gen survey=2002
	label var survey "ELS 2002 survey"
	gen wave=2
	label var wave "Survey time:(2 Years Aft HS)"
	gen weight=f2qwt
	
	ren byregion region
	label var region "schools' region"
	
	recode mot_edu (1=0) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8=7) (-9/-4=.)
	gen mot_hs=mot_edu>=1 if mot_edu~=.
	
	recode fat_edu (1=0) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8=7) (-9/-4=.)
	gen fat_hs=fat_edu>=1 if fat_edu~=.

	label var fat_hs "Dummy: 1 if respondent's father graduted from a HS"
	label var mot_hs "Dummy: 1 if respondent's mother graduted from a HS"
	
	recode fam_inc (1=0) (2=1000) (3=5000) (4=10000) (5=15000) (6=20000) ///
	(7=25000) (8=35000) (9=50000) (10=75000) (11=100000) (12=200000) (13=300000)
	
	replace fam_inc=fam_inc*(237/177.1)
	label var fam_inc "Family income adjusted for inflation"
	
	recode race_by (-8/-4=.)
	gen white=race_by==7 if race_by~=.
	gen black=race_by==3 if race_by~=.
	gen hispanic=race_by==4|race_by==5 if race_by~=.
	gen oth_race=race_by==1|race_by==2|race_by==6 if race_by~=.
	
	recode sex_by (-8/-4=.)
	gen female=sex_by==2 if sex_by~=.
	
		gen not_white=.
		replace not_white=1 if black==1|hispanic==1|oth_race==1
		replace not_white=0 if white==1
	
	label var white "Dummy: 1 if respondent is a white"
	label var black "Dummy: 1 if respondent is black"
	label var hispanic "Dummy: 1 if respondent is hispanic"
	label var oth_race "Dummy: 1 if respondent is other race"
	label var female "Dummy: 1 if respondent is female"
	
	* The following voluntary type questions asked 2 year after HS grad
	 rename f2d09 hs2_perf_vol_2yrs
	 recode hs2_perf_vol_2yrs (-9/-4=.)
	 
	 gen hs2_yes_perf_vol_2yrs=hs2_perf_vol_2yrs==1 if hs2_perf_vol_2yrs~=.
	 label var hs2_yes_perf_vol_2yrs ///
	 "Dummy: 1 During the past 2 yrs, have you perform any voluntary "

	** Whether has an HS diploma
	recode  f2hsstat (1/4=1) (10=.)
	gen hs2_high_sch= f2hsstat==1 if  f2hsstat~=.
	label var hs2_high_sch "Dummy: 1 if repondent has a HS diploma"
	
	** Postsecondary Education
	recode  f2b07 (-9/-3=.)
	gen hs2_att_PSE= f2b07==1 if  f2b07~=.
	label var hs2_att_PSE "Dummy: 1 ever attanded PSE institution"
	
	* College Education
	recode f2psej06 (-4=.) (-8=.) (-9=.) 
	gen  hs2_att_4_yr_PSE=1 if (f2psej06==1|f2psej06==4)&f2psej06~=.
	replace hs2_att_4_yr_PSE=0 if f2psej06~=.&hs2_att_4_yr_PSE~=1
	label var hs2_att_4_yr_PSE "Dummy: 1 ever attanded 4 year college"
	
	* Voluntary Particapation
	gen vltnry_prtcptn=1 if hs2_yes_perf_vol_2yrs==1
	replace vltnry_prtcptn=0 if hs2_yes_perf_vol_2yrs==0
	label var vltnry_prtcptn ///
	"Dummy:1 if respondent ever involved in voluntary activities"

	* Postsecondary Education
	gen post_scndry=1 if hs2_att_PSE==1 
	replace post_scndry=0 if hs2_att_PSE==0
	
	label var post_scndry "Dummy: 1 ever attanded PSE institution"
	
	keep  fips_state ncesid survey wave stu_id sch_id mot_hs fat_hs ///
	white black hispanic oth_race female vltnry_prtcptn post_scndry ///
	fam_inc vote_le vote_pe weight hs2_high_sch region not_white 
	
	drop if ncesid==-8|ncesid==-3 //dropped missing district with missing IDs
	
	save  "C:\Users\EAsker\Desktop\ABR\els_02\RFELS02_Clean_data\Round_2_RFELS02.dta", replace 
	
	*************************
	clear all
	set more off
	
	use "C:\Users\EAsker\Desktop\ABR\els_02\RFELS02_Clean_data\Round_1_RFELS02.dta"
	
	merge 1:1 stu_id using "C:\Users\EAsker\Desktop\ABR\els_02\RFELS02_Clean_data\Round_2_RFELS02.dta"
	
	drop _merge
	
	save "C:\Users\EAsker\Desktop\ABR\els_02\RFELS02_Clean_data\Round_1_2_RFELS02",replace
	
********************************************************************************
*************************************** Round 3 ******************************** 
********************************************************************************
		
	clear all
	set more off
	set maxvar 15000
	
	use "C:\Users\EAsker\Desktop\ABR\els_02\RFELS02_data\ELS2002_stdnt.dta",clear 

	rename *, lower
	
	rename (bymothed byfathed byincome byrace bysex bystuwt ncesdi bystate) ///
	(mot_edu fat_edu fam_inc race_by sex_by by_weight ncesid fips_state )
		
	gen survey=2002
	label var survey "ELS 2002 survey"
	gen wave=3
	label var wave "Survey time: (8 Years Aft HS)"
	gen weight=f3qwt
	
	ren byregion region
	label var region "schools' region"
	
	recode mot_edu (1=0) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8=7) (-9/-4=.)
	gen mot_hs=mot_edu>=1 if mot_edu~=.

	recode fat_edu (1=0) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8=7) (-9/-4=.)
	gen fat_hs=fat_edu>=1 if fat_edu~=.

	label var fat_hs "Dummy: 1 if respondent's father graduted from a HS"
	label var mot_hs "Dummy: 1 if respondent's mother graduted from a HS"

	
	recode fam_inc (1=0) (2=1000) (3=5000) (4=10000) (5=15000) (6=20000) ///
	(7=25000) (8=35000) (9=50000) (10=75000) (11=100000) (12=200000) (13=300000)
	
	replace fam_inc=fam_inc*(237/177.1) //multiplying with the deflator
	
	label var fam_inc "Family income adjusted for inflation"
	
	recode race_by (-8/-4=.)
	gen white=race_by==7 if race_by~=.
	gen black=race_by==3 if race_by~=.
	gen hispanic=race_by==4|race_by==5 if race_by~=.
	gen oth_race=race_by==1|race_by==2|race_by==6 if race_by~=.
	
	recode sex_by (-8/-4=.)
	gen female=sex_by==2 if sex_by~=.
	
		gen not_white=.
		replace not_white=1 if black==1|hispanic==1|oth_race==1
		replace not_white=0 if white==1
	
	label var white "Dummy: 1 if respondent is a white"
	label var black "Dummy: 1 if respondent is black"
	label var hispanic "Dummy: 1 if respondent is hispanic"
	label var oth_race "Dummy: 1 if respondent is other race"
	label var female "Dummy: 1 if respondent is female"
	
	 *	Voluntary Particapation
	 rename f3d40 hs8_perf_vol_2yrs
	 recode hs8_perf_vol_2yrs (-9/-4=.)
	 
	 gen hs8_yes_perf_vol_2yrs=hs8_perf_vol_2yrs==1 if hs8_perf_vol_2yrs~=.
	 label var hs8_yes_perf_vol_2yrs ///
	 "Dummy: 1 During the past 2 yrs, have you perform any voluntary "
	
	 *	Postsecondary
	recode f3evratt (-8=.) (-4=.)
	rename f3evratt hs8_att_PSE
	
	recode f3evr4yr (-9/-3=.) 
	gen hs8_att_4_yr_PSE=f3evr4yr==1 if f3evr4yr~=.
	label var hs8_att_4_yr_PSE "Dummy: 1 ever attanded a 4-year institution"
	
	*	Voluntary Particapation
	gen vltnry_prtcptn=1 if hs8_yes_perf_vol_2yrs==1
	replace vltnry_prtcptn=0 if hs8_yes_perf_vol_2yrs==0
	
	label var vltnry_prtcptn "Dummy:1 if respondent ever involved in voluntary activities"
	
	*	Voting Registration
	
	recode f3d37 (-9/-3=.)
	gen register_vote=f3d37==1 if f3d37~=.
	label var register_vote "Vote: Registered to Vote"
	
	*	Postsecondary Education
	gen post_scndry=1 if hs8_att_PSE==1 
	replace post_scndry=0 if hs8_att_PSE==0
	
	label var post_scndry "Dummy: 1 ever attanded PSE institution"
	
	
	keep  fips_state ncesid survey wave stu_id sch_id mot_hs fat_hs white ///
	black hispanic oth_race female vltnry_prtcptn post_scndry register_vote ///
	fam_inc   weight  region not_white
	
	drop if ncesid==-8|ncesid==-3
	
	save "C:\Users\EAsker\Desktop\ABR\els_02\RFELS02_Clean_data\Round_3_RFELS02",replace
	
	***************************************************************************
	********************** Append Round (1, 2 and 3)***************************
	***************************************************************************
	clear all
	set more off
	
	use   "C:\Users\EAsker\Desktop\ABR\els_02\RFELS02_Clean_data\Round_1_2_RFELS02"
	append using "C:\Users\EAsker\Desktop\ABR\els_02\RFELS02_Clean_data\Round_3_RFELS02"
	
	/* High school graduation status is determined by combining surveys 
	conducted in the summer after 12th grade and two years later.*/
	
	gen high_school=hs1_high_sch
	replace high_school=hs2_high_sch if (high_school==.|high_school==0)&hs2_high_sch~=.
	replace high_school=hs2_high_sch if hs2_high_sch~=.&high_school==.
	
	save "C:\Users\EAsker\Desktop\ABR\els_02\RFELS02_Clean_data\RFELS02", replace 
	
	
	
	
	
	